﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using SharpMap.Data;
using SharpMap.Layers;
using SharpMap.Geometries;
using System.Windows.Forms;
using MsSpatialTools;
namespace QueryVisualizerTools
{
    public class TabHelper
    {
        private string _FeatureColumns = "";
        public TabHelper(string Database)
        {
            DBHelper.Database = Database;
        }
        public TabHelper()
        {
        }
        public void addToTab(DataSet ds,TabControl tc)
        {
            this.removeTabPage(tc);
            this.removeByte(ds);
            string head = "属性数据--";
            foreach (DataTable  dt in ds.Tables)
            {
                TabPage tp = new TabPage(head + dt.TableName);
                tp.Dock = DockStyle.Top;
                tc.Controls.Add(tp);
                //tp.Size = tc.Size;

                DataGridView dgv = new DataGridView();
                dgv.DataSource = dt;
                dgv.Dock = DockStyle.Fill;
                tp.Controls.Add(dgv);
                //dgv.Size = tp.Size;
            }
            //this.dgvProperty.DataSource = dt;
             
        }
        private void removeTabPage(TabControl tc)
        {
            while (tc.Controls.Count > 1)
            {
                tc.Controls.RemoveAt(1);
            }
        }
        private void removeByte(DataSet ds)
        {
            for (int i = 0; i < ds.Tables.Count; i++)
            {
                DataTable dt=ds.Tables[i];
                foreach (DataColumn dc in dt.Columns)
                {
                    if (dc.DataType.Name.ToLower().Equals("byte[]"))
                    {
                        dt.Columns.Remove(dc);                         
                        break;
                    }
                }
            }
        }
        //private FeatureDataSet getFeatureDataSet(VectorLayer vl)
        //{

        //}
        //private void getDataTable(DataTable dt)
        //{ 

        //}
    }
}
